<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
global $language;
$language = 'en';
header( 'Content-type: text/html; charset=utf-8' );
include_once( "global/old_database_connection.php" );
include( "global/translations.php" );
$query5 = "SELECT language, title " .
		"FROM languages " .
		"ORDER BY title";
$result5 = mysql_query( $query5 ) or die( "Query failed : " . mysql_error() );
$num5 = mysql_numrows( $result5 );
if( isset( $_GET[ 'language' ] ) ) {
	$i = 0;
	while ( $i < $num5 ) {
		if( $_GET[ 'language' ] == mysql_result( $result5, $i, 'language' ) ) {
			$language = mysql_result( $result5, $i, 'language' );
			break;
		}
		$i ++;
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>Ages of Strife: <?php transprint( 'Hall of Fame' ); ?></title>
		<link type="text/css" rel="stylesheet" href="global/agesofstrife.css"></link>
	</head>
	<body>
		<div id="root_container">
			<div align="center" id="header-image">
				<a href="index.php?language=<?php print( $language ); ?>">
					<img class="header-dummy-image" src="resources/dummy.gif" alt="Ages of Strife" border="0" />
				</a>
			</div>
<?php
include( "global/ads.php" );
?>
			<div id="container">
				<div id="main-content">
					<h2>
						Ages of Strife <?php transprint( 'Hall of Fame' ); ?>
					</h2>
					<div id="blok">
						<?php transprint( 'Click' ); ?> <a href="rounds.php?language=<?php print( $language ); ?>"><?php transprint( 'here' ); ?></a> <?php transprint( 'to go back to the rounds.' ); ?><br />
						<br />
<?php
	include_once( "global/old_database_connection.php" );
	include( "global/utils.php" );
	if( isset( $_GET[ 'round' ] ) ) {
		$round = formatInput( urldecode( $_GET[ 'round' ] ) );
	}
	else {
		$round = '';
	}
	$query = "SELECT * FROM round WHERE round.show = 1 AND name = '" . $round . "'";
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$row = mysql_fetch_array( $result, MYSQL_ASSOC );
	if( isset( $row[ 'round_id' ] ) ) {
		$round_id = $row[ 'round_id' ];
		
		print( translate( 'Round' ) . ": <strong>" . $round . "</strong><br />\r\n<br />\r\n" );
	    print( translate( 'Turns' ) . ": " . number_format( $row[ 'turns' ] ) . "<br />\r\n" );
	    print( translate( 'Rulers' ) . ": " . number_format( $row[ 'rulers' ] ) . "<br />\r\n" );
	    print( translate( 'Villages' ) . ": " . number_format( $row[ 'villages' ] ) . "<br />\r\n" );
	    print( translate( 'World population' ) . ": " . number_format( $row[ 'population' ] ) . "<br />\r\n" );
?>
					</div><br />
<?php
		$query = "SELECT * FROM hall_of_fame WHERE round_id = $round_id AND faction = '0' ORDER BY economy DESC LIMIT 10";
		$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
		$num = mysql_numrows( $result );
		$i = 0;
		if( $num > 0 ) {
		?>
						<table>
							<tr><th colspan="7">
								<?php transprint( 'Top 10 economy points' ); ?>
							</th></tr>
							<tr>
								<td><?php transprint( 'Rank' ); ?></td>
								<td><?php transprint( 'Name' ); ?></td>
								<td><?php transprint( 'Economy points' ); ?></td>
								<td><?php transprint( 'Score' ); ?></td>
								<td><?php transprint( 'War points' ); ?></td>
								<td><?php transprint( 'Battle score' ); ?></td>
								<td><?php transprint( 'Villages' ); ?></td>
							</tr>
		<?php 
		while( $i < $num ) {
			if( $i % 2 == 0 ) {
		        print "<tr id=\"even\">";
		    }
		    else {
		        print "<tr>";
		    }
		    print( "<td align=\"right\">" . ( $i + 1 ) . "</td>" );
		    print( "<td>" . mysql_result( $result, $i, "name" ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "economy" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "score" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "war" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "battle_score" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "villages" ) ) . "</td>" );
		    print( "</tr>\r\n" );			
			$i ++;
		}
		?>
						</table>
		<?php
		}
		else {
			print( "No recorded users." );
		}
		
		$query = "SELECT * FROM hall_of_fame WHERE round_id = $round_id AND faction = '0' ORDER BY war DESC LIMIT 10";
		$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
		$num = mysql_numrows( $result );
		$i = 0;
		if( $num > 0 ) {
		?>
						<br />
						<table>
							<tr><th colspan="7">
								<?php transprint( 'Top 10 war points' ); ?>
							</th></tr>
							<tr>
								<td><?php transprint( 'Rank' ); ?></td>
								<td><?php transprint( 'Name' ); ?></td>
								<td><?php transprint( 'War points' ); ?></td>
								<td><?php transprint( 'Battle score' ); ?></td>
								<td><?php transprint( 'Economy points' ); ?></td>
								<td><?php transprint( 'Score' ); ?></td>
								<td><?php transprint( 'Villages' ); ?></td>
							</tr>
		<?php 
		while( $i < $num ) {
			if( $i % 2 == 0 ) {
		        print "<tr id=\"even\">";
		    }
		    else {
		        print "<tr>";
		    }
		    print( "<td align=\"right\">" . ( $i + 1 ) . "</td>" );
		    print( "<td>" . mysql_result( $result, $i, "name" ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "war" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "battle_score" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "economy" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "score" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "villages" ) ) . "</td>" );
		    print( "</tr>\r\n" );			
			$i ++;
		}
		?>
						</table>
		<?php
		}
		else {
			print( "<br />" .translate( 'No recorded users' ) . ".<br />" );
		}

		$query = "SELECT * FROM hall_of_fame WHERE round_id = $round_id AND faction = 1 ORDER BY score DESC LIMIT 10";
		$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
		$num = mysql_numrows( $result );
		$i = 0;
		if( $num > 0 ) {
		?>
						<br />
						<table>
							<tr><th colspan="9">
								<?php transprint( 'Top 10 factions' ); ?>
							</th></tr>
							<tr>
								<td><?php transprint( 'Rank' ); ?></td>
								<td><?php transprint( 'Name' ); ?></td>
								<td><?php transprint( 'Score' ); ?></td>
								<td><?php transprint( 'Economy points' ); ?></td>
								<td><?php transprint( 'Battle score' ); ?></td>
								<td><?php transprint( 'War points' ); ?></td>
								<td><?php transprint( 'Leader' ); ?></td>
								<td><?php transprint( 'Members' ); ?></td>
								<td><?php transprint( 'Average score' ); ?></td>
							</tr>
		<?php 
		while( $i < $num ) {
			if( $i % 2 == 0 ) {
		        print "<tr id=\"even\">";
		    }
		    else {
		        print "<tr>";
		    }
		    print( "<td align=\"right\">" . ( $i + 1 ) . "</td>" );
		    print( "<td>" . mysql_result( $result, $i, "name" ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "score" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "economy" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "battle_score" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "war" ) ) . "</td>" );
		    print( "<td>" . mysql_result( $result, $i, "leader" ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( mysql_result( $result, $i, "members" ) ) . "</td>" );
		    print( "<td align=\"right\">" . number_format( round( mysql_result( $result, $i, "score" ) / mysql_result( $result, $i, "members" ) ) ) . "</td>" );
		    print( "</tr>\r\n" );			
			$i ++;
		}
		?>
						</table>
		<?php
		}
		else {
			print( "<br />" . translate( 'No recorded users.' ) . "<br />" );
		}
	}
	else {
		transprint( 'Not a valid round name!' );
		print( "</div>\r\n" );
	}
?>
				</div>
			</div>
		</div>
	</body>
</html>